<!--
 * @Author: quit
 * @Date: 2021-11-23 10:13:56
 * @LastEditTime: 2021-12-02 13:31:09
 * @Descripttion: 模板:搜索 按钮组 表格
-->
<template>
  <div id="-container">
    <div class="app-container">
      <el-card>
        <!-- 搜索区域 -->
        <el-row class="row1">
          <el-divider content-position="left">{{ $t('divider.divider1') }}</el-divider>
          <div class="search">
            <el-form :inline="true" :model="searchForm" class="demo-form-inline">
              <el-form-item :label="$t('table.appName')">
                <el-input v-model="searchForm.appname" :placeholder="$t('input.searchPlaceholder')" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-zoom-in">{{ $t('button.search') }}</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-row>
        <!-- 按钮组 -->
        <el-row>
          <el-button type="primary" size="mini" icon="el-icon-circle-plus-outline" @click="addItems">{{ $t('button.addItems') }}</el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="batchRemove">{{ $t('button.batchRemove') }}</el-button>
        </el-row>
        <!-- 表格 -->
        <el-row>
          <el-table v-loading="loading" :data="tableData" :empty-text="$t('table.emptyText')" style="width: 100%">
            <el-table-column type="selection" min-width="40" fixed="left" />
            <el-table-column prop="appid" label="ID" min-width="45" fixed="left" />
            <el-table-column prop="appname" :label="'appname'" min-width="120" fixed="left" />
            <el-table-column header-align="center" align="center" fixed="right" :label="$t('table.operable')" min-width="290">
              <template slot-scope="scope">
                <el-button type="success" size="mini" @click="editHandle(scope.row)">{{ $t('button.edit') }}</el-button>
                <el-button type="danger" size="mini" @click="deleteHandle(scope.row)">{{ $t('button.delete') }}</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页 -->
          <el-pagination
            :current-page="pages.page"
            :page-sizes="[1, 5, 10]"
            :page-size="pages.size"
            layout="prev, pager, next, total, sizes, jumper"
            :total="pages.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </el-row>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      searchForm: { appname: '' },
      formInline: {
        user: '',
        region: ''
      },
      loading: false,
      tableData: [],
      pages: {
        page: 1,
        size: 10,
        total: 0
      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  created() {}, // 生命周期 - 创建完成（可以访问当前this实例）
  mounted() {}, // 生命周期 - 挂载完成（可以访问DOM元素）
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
  // 方法集合
  methods: {
    // 添加项目
    addItems() {},
    // 删除项目
    batchRemove() {},
    // table-itme项修改
    editHandle() {},
    // table-itme项删除
    deleteHandle() {},
    // 分页显示条数切换
    handleSizeChange(newSize) {
      this.pages.size = newSize
    },
    // 分页当前页切换
    handleCurrentChange(newPage) {
      this.pages.page = newPage
    }
  }
}
</script>

<style scoped>
.el-table {
  margin-top: 10px;
}
.el-pagination {
  margin-top: 10px;
}
.el-form {
  margin-left: 0;
}
</style>

<style lang="scss" scoped>
.row1 {
  margin-bottom: 10px;
  .search {
    border: 1px solid #dcdfe6;
    border-top: none;
    padding: 34px 10px 10px 10px;
    margin-top: -14px;
    .el-input {
      width: 300px;
    }
  }
}
</style>
